﻿//文件指定编译编码UTF-8
#pragma execution_character_set("utf-8")


#include "scanrulesavedialog.h"
#include "ui_scanrulesavedialog.h"
#include <QFileDialog>

ScanRuleSaveDialog::ScanRuleSaveDialog(ScanRule *object,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ScanRuleSaveDialog)
{
    ui->setupUi(this);
    objectInfo = object;
    if(objectInfo->getId() != 0){
        setWindowTitle("修改策略");
        ui->filterName->setText(objectInfo->getFilterName());
        ui->disposeMode->setCurrentIndex(objectInfo->getDisposeMode());
        ui->replacePath->setText(objectInfo->getReplacePath());
    }else{
        setWindowTitle("添加策略");
    }
}

ScanRuleSaveDialog::~ScanRuleSaveDialog()
{
    delete ui;
}

void ScanRuleSaveDialog::on_cancelBtn_clicked()
{
    QDialog::reject();
}

void ScanRuleSaveDialog::on_saveBtn_clicked()
{
    objectInfo->setFilterName(ui->filterName->text());
    objectInfo->setDisposeMode(ui->disposeMode->currentIndex());
    objectInfo->setReplacePath(ui->replacePath->text());
    QDialog::accept();
}

void ScanRuleSaveDialog::on_toolButton_clicked()
{
    QString openDir = QFileInfo(ui->replacePath->text()).dir().path();

    QString path = QFileDialog::getOpenFileName(this,QString("选择替换文件路径"),openDir,"*.*");
    if(!path.isEmpty()){
        ui->replacePath->setText(path);
    }
}
